//
//  Person.m
//  LessonOC06
//
//  Created by lanou on 15/9/25.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "Person.h"

@implementation Person

- (id)initWithName:(NSString *)aName age:(int)aAge sex:(NSString *)aSex
{
    self = [super init];
    if (self) {
        self.name = aName;
        self.sex  = aSex;
        self.age = aAge;
    }
    return self;
}

- (NSComparisonResult)sortByAge:(Person *)person
{
    if (self.age > person.age) {
        return NSOrderedAscending;
    } else if (self.age < person.age) {
        return NSOrderedDescending;
    }
    return NSOrderedSame;
}

- (NSComparisonResult)sortByName:(Person *)person
{
    return [self.name compare:person.name];
}

- (NSComparisonResult)sortBySex:(Person *)person
{
    return [self.sex compare:person.sex];
} 




- (NSString *)description
{
    return [NSString stringWithFormat:@"name = %@, sex = %@, age = %d", self.name, self.sex, self.age];
}


@end
